// 模拟常用的高阶函数 map every some

// map
const map = (array, fn) => {
    let results = [];
    for (const value of array) {
        results.push(fn(value));
    }
    return results;
}

// 测试
// let arr = [1,2,3,4];
// arr = map(arr,item => item * item);
// console.log(arr);


// every 
const every = (array, fn) => {
    let result = true;
    for (const item of array) {
        result = fn(item);
        if(!result) break; 
    }
    return result;
}

// 测试
// let arr = [11,12,112,3];
// let r = every(arr, item => item > 10);
// console.log(r);


// some
const some = (array, fn) => {
    let result =false;
    for (const item of array) {
        result = fn(item);
        if(result) break;
    }
    return result;
}

// 测试
let arr = [11,112,112,3];
let r = some(arr, item => item % 2 === 0);
console.log(r);